#include "FlyweightFactory.h"
#include <iostream>
#include <string>
#include <cassert>

using namespace std;

FlyweightFactory::FlyweightFactory(){
	_flyweights.insert(make_pair("X",new ConcreteFlyweight));
	_flyweights.insert(make_pair("Y",new ConcreteFlyweight));
	_flyweights.insert(make_pair("Z",new ConcreteFlyweight));
}

FlyweightFactory::~FlyweightFactory(){
	map<string, Flyweight*>::iterator it;
	for (it = _flyweights.begin(); it != _flyweights.end(); it++)
	{
		if (it->second)
		{
			delete it->second;
			it->second = NULL;
		}
	}
	_flyweights.clear();
}

Flyweight* FlyweightFactory::GetFlyweight(const string& key){
	map<string, Flyweight*>::iterator it = _flyweights.find(key);
	return it->second;
}